const install = (Vue,vm) => {
	const updateUserInfo = async () => {
		//请求用户信息
		const userInfo = await vm.$u.api.getUserInfo()
		//存储用户信息
		vm.$u.vuex("vuex_user",userInfo)
	}
	//验证拦截
	const isLogin = ()=>{
		
		//存储源页面
		const {route,options} = getCurrentPages().pop()
		//获取参数
		const options_key = Object.keys(options)
		const params = options_key.reduce((pre,key) =>{
			return `${pre}${key}=${options[key]}&`.slice(0,-1)
		},"?")
		//存储
		uni.setStorageSync("source_page",route+params)
		//验证
		if(!vm.vuex_token){
			vm.$u.toast("请登录")
			setTimeout(()=>{
				vm.$u.route({
					type:"redirect",
					url:"pages/auth/login"
				})
			},1500)
			return false
		}
		return true
	}
	vm.$u.utils = {
		isLogin,
		updateUserInfo
	}
}

export default {
	install
}